<template>
  <a-card :bordered="false">
      <!-- 查询区域 -->
    <div class="table-page-search-wrappe">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人">
              <select-user-by-dep  :multi="true" v-model="queryParam.proposer"></select-user-by-dep>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="车牌号">
              <SelectCarInfoInput placeholder="请选择车牌号" :multi="false" v-model="queryParam.carNum"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请时间">
              <a-range-picker
                :allowClear="false"
                v-model="createTime"
                style="width: 100%"
                @change="createTimeChange"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('车辆维修信息统计表')" :disabled="isDisabledAuth('erpReporCarMaintainInfo:export')">导出</a-button>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:'180%'}"
        :components="draggableComponent"
        bordered
        rowKey="billNo"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="documentNo" slot-scope="text, record" @click="getDetail(record.billNo)">{{ text }}</a>
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

<!--        <span slot="action" slot-scope="text, record">-->
<!--            <a-button-->
<!--                class="ruleButton"-->
<!--                :ghost="true"-->
<!--                type="primary"-->
<!--                icon="edit"-->
<!--                @click="handleEdit(record)"-->
<!--                :disabled="isDisabledAuth('erpReporCarMaintainInfo:edit')"-->
<!--        />-->
<!--        <a-divider type="vertical"/>-->
<!--        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
<!--            <a-button-->
<!--                    class="ruleButton"-->
<!--                    :ghost="true"-->
<!--                    type="primary"-->
<!--                    icon="delete"-->
<!--                    :disabled="isDisabledAuth('erpReporCarMaintainInfo:delete')"/>-->
<!--        </a-popconfirm>-->
<!--        </span>-->

      </a-table>
    </div>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectCarInfoInput from '@/views/scy/components/SelectCarInfoInput'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import moment from 'moment';

  export default {
    name: 'ErpReporCarMaintainInfoList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      SelectUserByDep,
      SelectCarInfoInput
    },
    data () {
      return {
        description: '车辆维修信息统计表管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:50,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'单据编号',
            align:"center",
            dataIndex: 'billNo_dictText',
            width: 150,
            ellipsis: true,
            scopedSlots: { customRender: 'documentNo' },
          },
          {
            title:'申请人',
            align:"center",
            dataIndex: 'proposer_dictText',
            width: 100,
            ellipsis: true,
          },
          {
            title:'费用所属团队',
            align:"center",
            dataIndex: 'teamId_dictText',
            width: 150,
            ellipsis: true,
          },
          {
            title:'车牌号',
            align:"center",
            dataIndex: 'carNum_dictText',
            width: 150,
            ellipsis: true,
          },
          {
            title:'申请时间',
            align:"center",
            dataIndex: 'applicationTime',
            width: 120,
            ellipsis: true,
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,16):text)
            }
          },
          {
            title:'维修时间',
            align:"center",
            dataIndex: 'maintenanceTime',
            width: 120,
            ellipsis: true,
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,16):text)
            }
          },
          {
            title:'报修类型',
            align:"center",
            dataIndex: 'repairReportType_dictText',
            width: 120,
            ellipsis: true,
          },
          {
            title:'维修项目',
            align:"center",
            dataIndex: 'maintenanceItems',
            width: 150,
            ellipsis: true,
          },
          {
            title:'维修金额（元）',
            align:"center",
            dataIndex: 'maintenanceMoney',
            width: 120,
            ellipsis: true,
          },
          {
            title:'当前里程数（km）',
            align:"center",
            dataIndex: 'carKilometers',
            width: 150,
            ellipsis: true,
          }
        ],
        queryParam: {
          createStartTime: moment().startOf('month').format("YYYY-MM-DD"),
          createEndTime: moment(moment().month(moment().month()).endOf('month').valueOf()).format('YYYY-MM-DD')
        },
        // createTime: [moment().startOf('month').format("YYYY-MM-DD"),moment(t, dateFormat).add(1, 'months').startOf('month').format('YYYY-MM-DD')],
        createTime: [moment().startOf('month').format("YYYY-MM-DD"),moment(moment().month(moment().month()).endOf('month').valueOf()).format('YYYY-MM-DD')],
        url: {
          list: "/api/erp/modules/workbench/report/erpReporCarMaintainInfo/list",
          exportXlsUrl: "/api/erp/modules/workbench/report/erpReporCarMaintainInfo/exportXls",
        },
        isorter: {
          column: 'applicationTime',
          order: 'desc'
        },
        dictOptions:{},
        superFieldList:[],
        formUrlMobile: '/pages/synergy/erpCarMaintenanceList',
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      customRow(record){},
      createTimeChange(date, dateString) {
        this.$set(this.queryParam, 'createStartTime', dateString[0] + ' 00:00:00')
        this.$set(this.queryParam, 'createEndTime', dateString[1] + ' 23:59:59')
      },
      searchReset() {
        this.queryParam = {
          createStartTime: moment().startOf('month').format("YYYY-MM-DD"),
          createEndTime: moment(moment().month(moment().month()).endOf('month').valueOf()).format('YYYY-MM-DD')
        }
        this.createTime = [moment().startOf('month').format("YYYY-MM-DD"),moment(moment().month(moment().month()).endOf('month').valueOf()).format('YYYY-MM-DD')]
        console.log('传递的时间参数为：',this.createTime)
        this.loadData(1)
      },
      getDetail(id) {
        this.$router.push({
          path: `/oa/carmaintenance/ErpCarMaintenanceListDetail/${id}`,
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'billNo',text:'单据编号',dictCode:''})
        fieldList.push({type:'string',value:'proposer',text:'申请人',dictCode:''})
        fieldList.push({type:'string',value:'teamId',text:'费用所属团队',dictCode:''})
        fieldList.push({type:'string',value:'carNum',text:'车牌号',dictCode:''})
        fieldList.push({type:'date',value:'applicationTime',text:'申请时间'})
        fieldList.push({type:'date',value:'maintenanceTime',text:'维修时间'})
        fieldList.push({type:'string',value:'repairReportType',text:'报修类型',dictCode:''})
        fieldList.push({type:'string',value:'maintenanceItems',text:'维修项目',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'maintenanceMoney',text:'维修金额（元）',dictCode:''})
        fieldList.push({type:'string',value:'carKilometers',text:'当前里程数（km）',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
